package com.example.android.bluetoothchat.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.android.bluetoothchat.R;
import com.example.android.bluetoothchat.uitls.StringUtils;


/**
 * Created by Administrator on 2017/4/21.
 *
 * 停车纪录适配器
 */

public class StopRecordAdapter extends BaseListAdapter<RecordBean> {
    
    private static String TAG = "MyBlueBoothAdapter";
    Context context;
    
    public StopRecordAdapter(Context context) {
        super(context);
        this.context = context;
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.stop_record_item, null);
        }
        
        TextView tvDeviceName = (TextView) convertView.findViewById(R.id.tv_device_name);
        TextView tvDeviceAddress = (TextView) convertView.findViewById(R.id.tv_device_address);
        
        TextView tvEnterTime = (TextView) convertView.findViewById(R.id.tv_enter_time);
        TextView tvOutTime = (TextView) convertView.findViewById(R.id.tv_out_time);
        
        TextView tvCash = (TextView) convertView.findViewById(R.id.tv_cash);
        RecordBean bean = getItem(position);
        
        tvDeviceName.setText(context.getString(R.string.enter_user_name, bean.username));
        tvDeviceAddress.setText(context.getString(R.string.enter_user_id, bean.userid));
        
        // 显示进入时间
        if (!TextUtils.isEmpty(bean.enterTime) && !bean.enterTime.equalsIgnoreCase(RecordBean.DEF_TIME_SHOW)) {
            String entertime = StringUtils.getDateTimeWithYM(Long.parseLong(bean.enterTime));
            tvEnterTime.setText(context.getString(R.string.enter_time, entertime));
        }
        
        // 显示离开时间
        if (!TextUtils.isEmpty(bean.outTime)) {
            if (!bean.outTime.equalsIgnoreCase(RecordBean.DEF_TIME_SHOW)) {
                String outtime = StringUtils.getDateTimeWithYM(Long.parseLong(bean.outTime));
                tvOutTime.setText(context.getString(R.string.out_time, outtime));
            }
            else {
                tvOutTime.setText(context.getString(R.string.out_time, RecordBean.DEF_TIME_SHOW));
            }
        }
        // 显示车费
        tvCash.setText(context.getString(R.string.stop_cash, bean.cash));
        return convertView;
        
    }
}
